package com.gxa.modules.app.outpatient.reportqueries.controller;

import com.gxa.common.utils.Result;
import com.gxa.modules.app.outpatient.reportqueries.service.ReportQueriesService;
import com.gxa.modules.model.entity.hospital.Indicator;
import com.gxa.modules.model.entity.hospital.PathologyReport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 作者 yuanqiufeng
 * Date 2022/11/12
 */
@Api(tags = "报告查询")
@RestController
@RequestMapping("/report-queries")
public class ReportQueriesController {
    @Autowired
    private ReportQueriesService reportQueriesService;

    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }


    @ApiOperation(value = "根据日期和点击类型查询")
    @GetMapping("/list/{checkType}/{createDate}/{endDate}")
    @ApiResponses({
            @ApiResponse(code = 0,message = "success",response = PathologyReport.class)
    })
    public Result list(@PathVariable("checkType") Integer checkType, @PathVariable("createDate") Date startDate,@PathVariable("endDate") Date endDate){
        try{
            List<PathologyReport> pathologyReportList = this.reportQueriesService.queryAllPathologyReport(checkType, startDate, endDate);
            return new Result().ok(pathologyReportList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("查询失败,数据异常");
        }
    }


    @ApiOperation(value = "体检报告后面的点击条件查询体检详情")
    @GetMapping("/list/{patientId}/{type}")
    @ApiResponses({
            @ApiResponse(code = 0,message = "success",response = Indicator.class)
    })
    public Result queryById(@PathVariable("patientId") Integer patientId, @PathVariable("type") Integer type){
        try{
            List<Indicator> indicatorList = this.reportQueriesService.queryAllById(patientId, type);
            return new Result().ok(indicatorList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("查询失败,数据异常");
        }
    }



    @ApiOperation(value = "根据id报告的详情")
    @GetMapping("/list/{id}")
    @ApiResponses({
            @ApiResponse(code = 0,message = "success",response = PathologyReport.class)
    })
    public Result query(@PathVariable("id") Integer id){
        try{
            PathologyReport pathologyReport = this.reportQueriesService.query(id);
            return new Result().ok(pathologyReport);
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("查询失败,数据异常");
        }
    }



}
